<?php
namespace application\cms\controller\admin;


class Config{

    private $config;

    function __construct(){
        // 配置信息
        $sql="select * from ".tablename('rj_cms_config')." where name='应用配置' ";
        $config = $GLOBALS['db']->query($sql)->fetch();
        $this->config = json_decode( $config['value'],true );

    }

    //系统配置
    function index(){
        $config = $this->config ;

        require view('admin/config/config.tpl.php');
    }

    //保存
    function config_save(){
        if(!isset($_POST['title']) && $_POST['title']==''){
            message('站点名称不能为空',url([ _MODULE_NAME_ ,'admin/config','index']));
        }
        //修改内容
        $data = $this->config ;

        $data['title'] = $_POST['title'] ;
        $data['logo_url'] = isset($_POST['logo_url'])?$_POST['logo_url']:'';
        $data['meta_keywords'] = $_POST['meta_keywords'];
        $data['meta_description'] = $_POST['meta_description'];
        $data['copyright'] = $_POST['copyright'];
        $data['icp'] = $_POST['icp'];
        $data['hidden_area'] = $_POST['hidden_area'];

        $data = [
            'value' => json_encode($data),
            'update_time' => date('Y-m-d H:i:s'),
        ];
        //条件
        $where['name'] = '应用配置';
        //执行sql
        $ok = pdo_update('rj_cms_config',$data,$where);

        if($ok){
            message('修改成功',url([ _MODULE_NAME_ ,'admin/config','index']));
        }else{
            message('修改失败',url([ _MODULE_NAME_ ,'admin/config','index']));
        }
        
    }
    

}
